#include "info.h"


int device_count()
{
    int device_count = 0;
    cudaGetDeviceCount(&device_count);
    return device_count;
}

std::ostream& operator<<(std::ostream& os, const Version& version)
{
    return os << version.major << "." << version.minor;
}

Version get_driver_version()
{
    int driver_version = 0;
    cudaDriverGetVersion(&driver_version);
    Version v;
    v.major = driver_version / 1000;
    v.minor = (driver_version % 1000) / 10;
    return v;
}

Version get_runtime_version()
{
    int runtime_version = 0;
    cudaRuntimeGetVersion(&runtime_version);
    Version v;
    v.major = runtime_version / 1000;
    v.minor = (runtime_version % 1000) / 10;
    return v;
}

cudaDeviceProp get_device_prop(int device)
{
    cudaDeviceProp prop;
    cudaGetDeviceProperties(&prop, device);
    return prop;
}

size_t get_global_memory_size(const cudaDeviceProp& prop)
{
    return prop.totalGlobalMem;
}

size_t get_sm_number(const cudaDeviceProp& prop)
{
    return prop.multiProcessorCount;
}

size_t get_shm_size_per_sm(const cudaDeviceProp& prop)
{
    return prop.sharedMemPerBlock;
}

size_t get_register_size_per_sm(const cudaDeviceProp& prop)
{
    return prop.regsPerBlock;
}

size_t get_warp_size(const cudaDeviceProp& prop)
{
    return prop.warpSize;
}

size_t get_max_threads_per_sm(const cudaDeviceProp& prop)
{
    return prop.maxThreadsPerMultiProcessor;
}

size_t get_max_threads_per_block(const cudaDeviceProp& prop)
{
    return prop.maxThreadsPerBlock;
}

size_t get_memory_band_width(const cudaDeviceProp& prop)
{
    return prop.memoryBusWidth;
}
